package com.jtny.nytb.config.dataalarm.controller;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.jtny.component.entity.PageData;
import com.jtny.component.entity.WebResponse;
import com.jtny.component.exception.ServiceException;
import com.jtny.nytb.config.dataalarm.service.DataAlarmBiz;
import com.jtny.nytb.config.dataalarm.vo.DataAlarmPageQueryParamVO;
import com.jtny.nytb.config.dataalarm.vo.DataAlarmVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * 数据报警点管理类
 *
 * @author 智慧能源中心 - zx
 * @package com.jtny.nytb.config.generic.dataalarm.controller
 * @fileName EquipmentInfoController.java
 * @createTime 2023年10月16日 10:47
 * @Copyright© 2023 jtny
 * 江投能源技术研究院 版权所有
 */
@RestController
@Api(value = "数据报警点管理", tags = "数据报警点管理")
@ApiSort(102025)
@RequestMapping("/config/dataalarm")
public class DataAlarmController {

    private static final String OPER_SUCCESS_MESSAGE = "操作成功！";

    @Autowired
    private DataAlarmBiz dataAlarmBiz;

    /**
     * 保存数据报警点管理
     *
     * @param dataAlarmVO
     * @return
     */
    @ApiOperation("保存数据报警点管理")
    @ApiImplicitParam(name = "dataAlarmVO", value = "保存数据报警点管理", required = true, paramType = "query", dataType = "DataAlarmVO")
    @ApiOperationSupport(order = 1)
    @PostMapping("/save")
    @ResponseBody
    public WebResponse<?> saveDataAlarm(@RequestBody DataAlarmVO dataAlarmVO) {
        try {
            DataAlarmVO dataAlarmVOFirst = dataAlarmBiz.saveDataAlarm(dataAlarmVO);
            return WebResponse.success(OPER_SUCCESS_MESSAGE);
        } catch (ServiceException e) {
            return WebResponse.error(e);
        }

    }

    /**
     * 修改数据报警点管理
     *
     * @param dataAlarmVO
     * @return
     */
    @ApiOperation("修改数据报警点管理")
    @ApiImplicitParam(name = "dataAlarmVO", value = "保存数据报警点管理", required = true, paramType = "query", dataType = "DataAlarmVO")
    @ApiOperationSupport(order = 2)
    @PostMapping("/update")
    @ResponseBody
    public WebResponse<?> updateDataAlarm(@RequestBody DataAlarmVO dataAlarmVO) {
        try {
            DataAlarmVO dataAlarmVOFirst = dataAlarmBiz.updateDataAlarm(dataAlarmVO);
            return WebResponse.success(OPER_SUCCESS_MESSAGE);
        } catch (ServiceException e) {
            return WebResponse.error(e);
        }
    }

    /**
     * 报警点信息删除操作
     *
     * @param id
     * @return
     */
    @ApiOperation("报警点信息删除操作")
    @ApiImplicitParam(name = "id", value = "报警点id", required = true, paramType = "path")
    @ApiOperationSupport(order = 3)
    @GetMapping("/deleteDataAlarm/{id}")
    @ResponseBody
    public WebResponse<?> deleteDataAlarm(@PathVariable("id") Long id) {
        try {
            dataAlarmBiz.deleteDataAlarm(id);
            return WebResponse.success(OPER_SUCCESS_MESSAGE);
        } catch (ServiceException e) {
            return WebResponse.error(e);
        }

    }

    /**
     * 报警点信息详情操作
     *
     * @param id
     * @return
     */
    @ApiOperation("报警点信息详情操作")
    @ApiImplicitParam(name = "id", value = "报警点id", required = true, paramType = "path")
    @ApiOperationSupport(order = 4)
    @GetMapping("/detailsDataAlarm/{id}")
    @ResponseBody
    public WebResponse<?> detailsDataAlarm(@PathVariable("id") Long id) {
        try {
            DataAlarmVO dataAlarmVO = dataAlarmBiz.detailsDataAlarm(id);
            return WebResponse.success(dataAlarmVO);
        } catch (ServiceException e) {
            return WebResponse.error(e);
        }

    }

    /**
     * 数据报警点管理信息分页查询操作
     *
     * @param dataAlarmPageQueryParamVO
     * @return
     */
    @ApiOperation("数据报警点管理信息分页查询操作")
    @ApiImplicitParam(name = "dataAlarmPageQueryParamVO", value = "数据报警点管理信息分页查询VO对象", required = true, paramType = "query", dataType = "DataAlarmPageQueryParamVO")
    @ApiOperationSupport(order = 5)
    @PostMapping("/queryPage")
    @ResponseBody
    public WebResponse<?> queryPage(@RequestBody DataAlarmPageQueryParamVO dataAlarmPageQueryParamVO) {
        try {
            PageData<DataAlarmVO> dataAlarmVOPageData = dataAlarmBiz.queryPage(dataAlarmPageQueryParamVO);
            return WebResponse.success(dataAlarmVOPageData);
        } catch (ServiceException e) {
            return WebResponse.error(e);
        }
    }


    /**
     * 下载报警点excel模板
     *
     * @param response
     */
    @ApiOperation("下载报警点excel模板")
    @ApiOperationSupport(order = 6)
    @GetMapping("/downloadTemplate")
    public void downloadDataAlarmTemplate(HttpServletResponse response) {
        dataAlarmBiz.downloadDataAlarmTemplate(response);
    }

    /**
     * 导入数据报警点管理信息操作
     * @param file
     * @return
     */
    @ApiOperation(value = "导入数据报警点管理信息操作")
    @ApiOperationSupport(order = 7)
    @PostMapping("/importDataAlarm")
    public WebResponse<?> importDataAlarm( @RequestParam("file") MultipartFile file) {

        if (file.isEmpty()) {
            throw new ServiceException("文件数据为填写，请注意检查一下");
        }
        try {
            dataAlarmBiz.importDataAlarm(file);
            return WebResponse.success("操作成功");
        } catch (ServiceException e) {
            return WebResponse.error(e);
        }

    }
}
